package com.zzit.vjv.CustomeInterceptor;

import com.zzit.vjv.entity.documentReview_entity.DevUser;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * 自定义前台拦截器
 */
public class Interceptor1 implements HandlerInterceptor {


    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {

        HttpSession session = request.getSession();

        DevUser devUser = (DevUser) session.getAttribute("devUserSession");

        if (null == devUser) {


            String basePath = request.getScheme() + "//:" + request.getServerName() + ":" + request.getServerPort();


            response.sendRedirect("http://localhost:8080/O/jsp/devlogin.jsp");


            //System.out.println("访问的地址"+handler);

            return false;

        }

        String basePath = request.getScheme() + "//:" + request.getServerName() + ":" + request.getServerPort();
        //response.sendRedirect("loing");

        System.out.println("会话"+devUser);

        return true;

    }

    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
        System.out.println("淦1");
    }

    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
        System.out.println("淦1");
    }
}
